package gek.uni.diplom.ocl.example.utils.junit;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

public class JUnitFileDesc {

  private Set<String> importStrings = new LinkedHashSet<String>();
  private String className;
  private Set<MethodDescription> methods = new LinkedHashSet<MethodDescription>();
  private Set<String> methodNames = new HashSet<String>();

  public void addImportStrings(String[] importStrings) {
    for (String str : importStrings) {
      this.importStrings.add(str);
    }
  }

  public void setClassName(String name) {
    this.className = name;
  }

  public void addMethodDescription(MethodDescription method) {
    addMethodDescription(method, null);
  }

  private void addMethodDescription(MethodDescription method, Integer number) {
    if (number == null) {
      if (methodNames.contains(method.getName()))
        addMethodDescription(method, new Integer(1));
      else {
        methods.add(method);
        methodNames.add(method.getName());
      }
    } else {
      if (methodNames.contains(method.getName() + String.valueOf(number)))
        addMethodDescription(method, new Integer(number + 1));
      else {
        MethodDescription copyMethod = new MethodDescription(method.getName()
            + String.valueOf(number), method.getBody());
        methods.add(copyMethod);
        methodNames.add(method.getName());
      }
    }
  }

}
